"""
通用响应模式
"""

from pydantic import BaseModel
from typing import Generic, TypeVar, List, Optional, Any
from datetime import datetime

from app.utils.timezone_utils import get_shanghai_now

T = TypeVar('T')


class BaseResponse(BaseModel, Generic[T]):
    """基础响应模式"""
    code: int = 200
    message: str = "success"
    success: bool = True
    timestamp: datetime = get_shanghai_now()
    data: Optional[T] = None


class DataResponse(BaseResponse[T]):
    """带数据的响应模式"""
    pass


class PaginationInfo(BaseModel):
    """分页信息"""
    current: int = 1
    pageSize: int = 10
    total: int = 0
    totalPages: int = 0


class PaginatedResponse(BaseModel, Generic[T]):
    """分页响应模式"""
    code: int = 200
    message: str = "success"
    success: bool = True
    timestamp: datetime = get_shanghai_now()
    data: List[T] = []
    pagination: PaginationInfo


class ErrorResponse(BaseResponse):
    """错误响应模式"""
    code: int = 500
    message: str = "Internal Server Error"
    success: bool = False
    error_detail: Optional[str] = None
